package com.easydisk.file.model.vo;

import com.easydisk.file.model.entity.UserFile;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.google.common.collect.Lists;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class FolderTreeVO  implements Serializable {

    /**
     * 节点显示标题
     */
    private String label;

    /**
     * 唯一标识
     */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    /**
     * 子节点
     */
    private List<FolderTreeVO> children;

    /**
     * 父文件夹ID
     */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long parentId;

    /**
     * 拼装树节点
     */
    public static FolderTreeVO assembleFolderTreeNode(UserFile userFile) {
        FolderTreeVO folderTreeNode = new FolderTreeVO();
        folderTreeNode.setLabel(userFile.getFilename());
        folderTreeNode.setId(userFile.getId());
        folderTreeNode.setChildren(Lists.newArrayList());
        folderTreeNode.setParentId(userFile.getParentId());
        return folderTreeNode;
    }

}
